package org.example.cicdi.service.impl.second;

import org.apache.commons.collections4.CollectionUtils;

import org.example.cicdi.enums.EnumWhiteColumnAnnotation;
import org.example.codegenerate.modelext.WebVo.domian.column.ColumnVoDomain;
import org.example.codegenerate.modelext.WebVo.domian.table.WebModelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

@Service
public class FieldfacaService {
    @Autowired
    private List<FieldAnnotationServiceSecond> fieldasslist;

   /* public void handleFieldVo(Class<?> cl, TableVoDomain tableVoDomain,List<WebModelVo> webModelVoList) {
        //Field[] fields = cl.getDeclaredFields();
        Field[] fields=AnnotationUtil.getAllFields(cl);
        if (fields == null || fields.length == 0) {
            // throw new Exception("对象可用字段为空");
        }

        List<ColumnVoDomain> list = new ArrayList<>();
        for (Field field : fields) {
            field.setAccessible(true);

            ColumnVoDomain columnVoDomain = new ColumnVoDomain();
            if (CollectionUtils.isEmpty(fieldasslist)) {
                break;
            }

            for (FieldAnnotationServiceSecond service : fieldasslist) {
                if (EnumWhiteColumnAnnotation.getByCode(service.getCode()) != null) {
                    service.handleFieldVo(field, columnVoDomain,tableVoDomain,webModelVoList);
                }
            }
            list.add(columnVoDomain);
        }
        tableVoDomain.setColumnVoDomainList(list);
    }*/
    public void handleFieldVo(Class<?> cl, WebModelVo webModelVo, List<WebModelVo> webModelVoList) {
        //TableVoDomain tableVoDomain=webModelVo.getTableVoDomain();
        //Field[] fields = cl.getDeclaredFields();
        Field[] fields=AnnotationUtil.getAllFields(cl);
        if (fields == null || fields.length == 0) {
            // throw new Exception("对象可用字段为空");
        }

        List<ColumnVoDomain> list = new ArrayList<>();
        for (Field field : fields) {
            field.setAccessible(true);

            ColumnVoDomain columnVoDomain = new ColumnVoDomain();
            if (CollectionUtils.isEmpty(fieldasslist)) {
                break;
            }
            if(field.getName().contains("testOrderMain")){
                int i=1;
            }
            if(field.getName().contains("DefaultTestOrderProduct")){
                int i=1;
            }


            for (FieldAnnotationServiceSecond service : fieldasslist) {
                if (EnumWhiteColumnAnnotation.getByCode(service.getCode()) != null) {
                    if(EnumWhiteColumnAnnotation.getByCode(service.getCode()).getCode().toLowerCase().contains("manytoone")){
                        int j=1;
                    }
                    service.handleFieldVo(field, columnVoDomain,webModelVo,webModelVoList);
                }
            }
            list.add(columnVoDomain);
        }
        webModelVo.getTableVoDomain().setColumnVoDomainList(list);
    }
}
